package com.hai.comtroller;

import com.hai.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 黄海 on 12/25/2016.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("login2.do")
    public String login2(String name, String pwd) {
        System.out.println(name + "=" + pwd);
        return "redirect:/jsp/success.jsp";
    }

    @RequestMapping("login.do")
    @ResponseBody//只返回字符
    public String login(String name, String pwd) {
        System.out.println(name + "=" + pwd);
        return "login success";
    }

    @RequestMapping(value = "/get.do",method = RequestMethod.GET)
    @ResponseBody//只返回字符
    public String get() {
        return "this is a return text for get test";
    }

    @RequestMapping(value = "/get2.do",method = RequestMethod.GET)
    @ResponseBody//只返回字符
    public User get2() {
        return new User("huang","hai");
    }

    @RequestMapping(value = "post.do",method = RequestMethod.POST)
    @ResponseBody//只返回字符
    public String post(String username, String password) {
        String content="post:name="+username+",pwd="+password;
        System.out.println(content);
        return "this is a post text:"+content;
    }
}
